package com.titan.demo.camel.sample.eip.使用enrich实现信息合并.camel.route;

import java.util.List;

import org.apache.camel.Exchange;
import org.apache.camel.processor.aggregate.AggregationStrategy;
import org.apache.camel.spring.SpringRouteBuilder;

public class DemoRouteBuilder extends SpringRouteBuilder {

	@Override
	public void configure() throws Exception {
		from("direct:start")
        .to("stream:out")
        .enrich("direct:resource", new AggregationStrategy() {
			public Exchange aggregate(Exchange original, Exchange resource) {
				Object originalBody = original.getIn().getBody();
				Object resourceResponse = resource.getIn().getBody();
				Object mergeResult = "original["+originalBody+"];  resource["+resourceResponse+"]"; 
				if (original.getPattern().isOutCapable()) {
					original.getOut().setBody(mergeResult);
				} else {
					original.getIn().setBody(mergeResult);
				}
				return original;
			}
        })
        .to("stream:out")
        ;

        from("direct:resource")
        .transform().simple("被合并数据")
        .setBody(body().append("。"))
        .to("stream:out")
        ;
	}

}
